package com.neolix.watch.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.AbsListView;

import com.neolix.watch.view.WeatherItemView;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static com.neolix.watch.domain.BaiDuWeatherResult.BaiDuWeatherData;

public class WeatherAdapter extends NeolixBaseAdapter<WeatherItemView> {
    private final int height;
    private List<BaiDuWeatherData> items = newArrayList();
    private Context context;

    public WeatherAdapter(Context context, int height) {
        this.context = context;
        this.height = height;
    }

    public void setData(List<BaiDuWeatherData> items) {
        this.items = items;
        notifyDataSetChanged();
    }

    @Override
    protected void updateView(WeatherItemView view, int position) {
        view.setModel(items.get(position));
    }

    @Override
    protected WeatherItemView buildView(ViewGroup parent) {
        WeatherItemView weatherItemView = new WeatherItemView(context);
        AbsListView.LayoutParams param = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, height);
        weatherItemView.setLayoutParams(param);
        return weatherItemView;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public BaiDuWeatherData getItem(int i) {
        return items.get(i);
    }
}
